<template>
  <div class="limitdivc">
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      :rules="rules"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-row>
        <el-col :span="18">
          <div class="grid-content bg-purple">
            <el-form-item label="停车费价格" prop="msg">
              <el-input v-model="ruleForm.msg" placeholder="请输入停车费价格，如：1.2">
                <template slot="append">元/月</template>
              </el-input>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple-light">
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        id: "",
        msg: ""
      },
      rules: {
        msg: [
          { required: true, message: "停车费价格不可为空", trigger: "blur" },
          {
            pattern: "(([0-9]|([1-9][0-9]{0,9}))((.[0-9]{1,2})?))$",
            message: "请输入正确价格"
          }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.axios
            .post("tage/setprice?tage=" + 6, this.ruleForm)
            .then(res => {
              this.$alert("添加或修改成功！！！", "操作成功", {
                confirmButtonText: "确定",
                callback: action => {
                  this.axios
                    .post("tage/managepow", this.ruleForm)
                    .then(res => {
                      if (res.data == "success"){
                       this.$router.push("/index_manager");
                       window.location.reload();
                      }
                      console.log(res);
                    })
                    .catch(err => {
                      console.error(err);
                    });
                }
              });
            })
            .catch(err => {
              console.error(err);
            });
          console.log(this.ruleForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  },
  created() {
    this.ruleForm.id = sessionStorage.getItem("userId");
  },
  components: {}
};
</script>

<style scoped>
.limitdivc {
  width: 500;
  margin: 0 auto;
  width: 70%;
}
</style>
